package top.ytazwc.proxy;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;

/**
 * @author 00103943
 * @date 2025-03-18 14:49
 * @package top.ytazwc.proxy
 * @Description
 */
public class CustomInvocationHandler implements InvocationHandler {

    private final Object target;

    public CustomInvocationHandler(Object target) {
        this.target = target;
    }

    @Override
    public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
        // 调用方法之前 添加自己的操作
        System.out.println("before method " + method.getName());
        Object res = method.invoke(target, args);
        // 调用方法之后 添加自己的操作
        System.out.println("after method " + method.getName());

        return res;
    }

}
